<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <script src="./vue.js"></script>
</head>
<body>
  <div id="app">
    <ol>
      <li v-for="todo in todos" :key="todo.id">
        {{todo.title}}
      </li>
    </ol>
  </div>
  <script>
    const app = new Vue({
      el: '#app',
      data: {
        todos: []
      },
      created () {
        // 一开始就会执行的代码
        // 原生的fetch，返回的是一个promise，返回的结果做了二次封装，所以第一个then里先解析
        fetch('https://jsonplaceholder.typicode.com/todos')
          .then(resp => resp.json())
          .then(todos => {
            this.todos = todos
          })
      }
    })
  </script>
</body>
</html>
